import request from '@/utils/request'
const role = localStorage.getItem('role')

/**
 * 获取应聘单位数据
 * @param {*}
 * @returns
 */
export function getRoleMold () {
  return request({
    url: '/api.php/Personnel/role_mold',
    method: 'post'
  })
}
/**
 * 获取权限选择数据
 * @param {*}
 * @returns
 */
 export function getPermissions () {
  return request({
    url: 'api.php/user/manage',
    method: 'post'
  })
}
/**
 * 获取人才岗位
 * @param {*}
 * @returns
 */
export function getRoleType () {
  return request({
    url: '/api.php/Personnel/personnel_sort',
    method: 'post'
  })
}

/**
 * 添加人才基本信息
 * @param {*} data
 * @returns
 */
export function addPersonnelInfo (data) {
  return request({
    url: '/api.php/Personnel/add',
    method: 'post',
    data
  })
}

/**
 * 保存人才基本信息
 * @param {*} data
 * @returns
 */
export function savePersonnelInfo (data) {
  return request({
    url: '/api.php/Personnel/personnel_keep_add',
    method: 'post',
    data
  })
}

/**
 * 保存主要信息
 * @param {*} data
 * @returns
 */
export function saveMainInfo (data) {
  return request({
    url: '/api.php/Personnel/personnel_main_hold',
    method: 'post',
    data
  })
}

export function getPersonnelInfo () {
  return request({
    url: '/api.php/Personnel/personnel_basic_edit',
    method: 'post'
  })
}

/**
 * 获取用户主要资料
 * @returns
 */
export function getMainInfo () {
  return request({
    url: '/api.php/Personnel/personnel_main_edit',
    method: 'post'
  })
}

/**
 * 获取人才分类
 * @returns
 */
export function getPersonnelType () {
  return request({
    url: '/api.php/Personnel/personnel_sort',
    method: 'post'
  })
}

function test () {
  let url = ''
  switch (role) {
    case '专家':
      url = '/api.php/expert/index'
      break
    case '评委':
      url = '/api.php/Judges/index'
      break
    case '学院':
      url = '/api.php/college/index'
      break
    case '管理员':
      url = '/api.php/admin/per_list'

      break
    case '超级管理员':
      url = '/api.php/admin/per_list'

      break

    default:
      break
  }
  return url
}

/**
 * 获取人才列表
 * @param {*} params
 * @returns
 */
export function getPersonnelList (params) {
  return request({
    url: test(),
    method: 'get',
    params
  })
}

/**
 * 获取人才详细资料
 * @param {*} data
 * @returns
 */
export function getPersonnelDetail (data) {
  let url = ''
  switch (role) {
    case '专家':
      url = '/api.php/expert/expert_edit'
      break
    case '评委':
      url = '/api.php/Judges/judges_edit'
      break
    case '管理员':
      url = '/api.php/admin/per_see'
      break
    case '学院':
      url = '/api.php/college/college_edit'
      break
    case '超级管理员':
      url = '/api.php/admin/per_see'
      break
    default:
      break
  }
  return request({
    url,
    method: 'post',
    data
  })
}

/**
 * 获取待分配人才列表
 * @param {*} params
 * @returns
 */
export function getAllocationList (params) {
  return request({
    url: '/api.php/admin/stay_allocation',
    method: 'get',
    params
  })
}

/**
 * 获取评审保存的详情
 * @param {*} data
 * @returns
 */
export function getExpertEvaluate (data) {
  return request({
    url: '/api.php/expert/expert_edit_keep',
    method: 'post',
    data
  })
}

/**
 * 保存专家评价信息
 * @param {*} data
 * @returns
 */
export function saveExpertEvaluate (data) {
  return request({
    url: '/api.php/expert/expert_review_keep',
    method: 'post',
    data
  })
}

/**
 * 提交专家评价信息
 * @param {*} data
 * @returns
 */
export function submitExpertEvaluate (data) {
  return request({
    url: '/api.php/expert/expert_review',
    method: 'post',
    data
  })
}

/**
 * 获取分配人员列表
 * @param {*} data
 * @returns
 */
export function getDistributionList (params) {
  return request({
    url: '/api.php/admin/distribution_list',
    method: 'get',
    params
  })
}

/**
 * 分配人员
 * @param {*} data
 * @returns
 */
export function allocationPersonnel (data) {
  return request({
    url: '/api.php/admin/distribution',
    method: 'post',
    data
  })
}

/**
 * 上传意见
 * @param {*} data
 * @returns
 */
export function uploadIdea (data) {
  return request({
    url: '/api.php/college/college_opinion',
    method: 'post',
    data
  })
}

/**
 * 保存评委评价信息
 * @param {*} data
 * @returns
 */
export function saveJudgeEvaluate (data) {
  return request({
    url: '/api.php/Judges/judges_review_keep',
    method: 'post',
    data
  })
}

/**
 * 提交评委评价信息
 * @param {*} data
 * @returns
 */
export function submitJudgeEvaluate (data) {
  return request({
    url: '/api.php/Judges/judges_review',
    method: 'post',
    data
  })
}

/**
 * 获取评委保存的信息
 * @param {*} data
 * @returns
 */
export function getJudgeEvaluateInfo (data) {
  return request({
    url: '/api.php/Judges/judges_edit_keep',
    method: 'post',
    data
  })
}

/**
 * 提交主要信息
 * @param {*} data
 * @returns
 */
export function submitMainInfo (data) {
  return request({
    url: '/api.php/Personnel/add_main',
    method: 'post',
    data
  })
}

/**
 * 个人信息下载
 * @param {*} data
 * @returns
 */
export function downloadResume (params) {
  return request({
    url: '/api.php/college/resume',
    method: 'get',
    responseType: 'blob',
    params
  })
}

/**
 * 管理端人才列表导出
 * @param {*} data
 * @returns
 */
export function exportPersonnelList (data) {
  return request({
    url: '/api.php/admin/per_export',
    method: 'post',
    responseType: 'blob',
    data
  })
}

/**
 * 获取模版文件链接
 * @returns
 */
export function getTemplate () {
  return request({
    url: '/api.php/Personnel/template',
    method: 'post'
  })
}

/**
 * 获取分配历史
 * @param {*} params
 * @returns
 */
export function getHistory (params) {
  return request({
    url: '/api.php/admin/distribution_edit',
    method: 'get',
    params
  })
}

/**
 * 完成分配
 * @param {*} data
 * @returns
 */
export function finishAllocation (data) {
  return request({
    url: '/api.php/admin/click_distribution',
    method: 'post',
    data: {
      ...data,
      states: 1
    }
  })
}

/**
 * 获取人才已分配专家评委列表
 * @param {*} data
 * @returns
 */
export function getAllocation (params) {
  return request({
    url: '/api.php/admin/assigned_list',
    method: 'get',
    params
  })
}

/**
 * 提交人才办意
 * @param {*} data
 * @returns
 */
export function PostOpinion (data) {
  return request({
    url: 'api.php/admin/manage_opinion',
    method: 'post',
    data
  })
}
